Fix #7776: Detect missing implementations for C# 'abstract override' methods#19503
Fix #7776: Detect missing implementations for C# 'abstract override' methods#19503
Conversation
|
@copilot : Try again |
|
@copilot : Try again. |
|
@copilot Try again |
Implemented the fix in commit ab7b03c. Root cause: The Fix: Added an 6 regression tests added, all 2871 Conformance tests pass with 0 regressions. |
ab7b03c to
d6e0d3a
Compare
❗ Release notes required
|
…methods The IgnoreOverrides filter in InfoReader.fs incorrectly removed abstract override methods (e.g. C# 'abstract override string ToString()') because they were signature-equivalent to the base virtual method. This caused GetClassDispatchSlots to miss these as required dispatch slots. The fix adds an isAbstract check to the FilterOverrides function so that abstract methods from derived types are preserved even when they override an equivalent virtual in a supertype. This ensures the compiler correctly reports FS0365 when a non-abstract F# class inherits from a C# class with abstract override members without providing implementations. Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/1d6d6e17-b57c-435f-b144-0d3146d9cbd8 Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/1d6d6e17-b57c-435f-b144-0d3146d9cbd8 Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
d6e0d3a to
f912571
Compare
The F# compiler did not report an error when a non-abstract F# class inherited from a C# class with
abstract overridemembers (e.g.,public abstract override string ToString()) without providing implementations. This caused aTypeLoadExceptionat runtime with no compile-time warning.Root Cause
The
IgnoreOverridesfilter inInfoReader.FilterOverrideswas incorrectly removing C#abstract overridemethods from the method set. These methods have IL flagsAbstract=true, Virtual=true, NewSlot=false, and the filter treated them as equivalent to the base virtual method they re-abstract (e.g.,Object.ToString()), discarding them. This causedGetClassDispatchSlotsto only see the original non-abstract base method, which was marked as "optional" (already has an implementation), so no FS0365 error was reported.Fix
Added an
isAbstractparameter to theFilterOverridesfunction inInfoReader.fs. In theIgnoreOverridespath, abstract methods from derived types are now preserved even when they're signature-equivalent to virtual methods in supertypes. This ensuresGetClassDispatchSlotscorrectly identifies abstract override methods as required (non-optional) dispatch slots.Changes
src/Compiler/Checking/InfoReader.fs: AddedisAbstracttoFilterOverridesparameter tuple and theIgnoreOverrideskeepTest condition so abstract re-declarations are not filtered out.tests/.../AbstractMembers/AbstractMembers.fs: Added 6 regression tests covering: missing implementation error forabstract override ToString(), missing implementation for custom abstract override method, successful compilation when implementation is provided, abstract F# subclass allowed without implementation, and object expression with implementation.docs/release-notes/.FSharp.Compiler.Service/11.0.100.md: Added release note.Testing
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.